﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;

namespace AgvPublic
{
    public class GetConfig
    {
        public static string GetConnectionStringsConfig(string connectionName)
        {
            string _connectionString = ConfigurationManager.ConnectionStrings[connectionName].ConnectionString.ToString();
            return _connectionString;
        }

        ///<summary> 
        ///返回*.exe.config文件中appSettings配置节的value项 
        ///</summary> 
        ///<param name="strKey"></param> 
        ///<returns></returns> 
        public static string GetAppConfig(string strKey)
        {
            string file = System.Windows.Forms.Application.ExecutablePath;
            Configuration config = ConfigurationManager.OpenExeConfiguration(file);
            foreach (string key in config.AppSettings.Settings.AllKeys)
            {
                if (key == strKey)
                {
                    return config.AppSettings.Settings[strKey].Value.ToString();
                }
            }
            return null;
        }

        public static List<string> GetAppConfigList()
        {
            List<string> allValue = new List<string>();
            string file = System.Windows.Forms.Application.ExecutablePath;
            Configuration config = ConfigurationManager.OpenExeConfiguration(file);
            foreach (string key in config.AppSettings.Settings.AllKeys)
            {
                allValue.Add(config.AppSettings.Settings[key].Value.ToString());
            }
            return allValue;
        }
 
    }
}
